<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="p" uri="/WEB-INF/tld/page.tld" %>
<script type="text/javascript">
	function turnpage(pageNo) {
		var url = "/user";
		if(pageNo!=null)
			url = url+"?pageNo="+pageNo;
		$("#content").load(url);
	}
	
	function editUser(id) {
		$.ajax({
			url:"/user/load/"+id,
			dataType:"json"
		}).done(function(data){
			var obj = changeData(data);
			var elements = $("#user-form").find("input,select");
			$.each(elements, function(i, n){
				var name = $(n).attr("name");
				name = name.replace("user.", "");
				var value = eval("obj."+name);
				$(n).val(value);
			})
			$("#user-dialog").modal("show");
		})
		//$("#user-dialog").modal("show");
	}
	
	function delUser(id) {
		if(window.confirm("确定要删除么？")) {
			$.ajax({
				url:"/user/del/"+id,
				dataType:"json"
			}).done(function(data){
				alert(data.msg);
				if(data.isSuccess) 
					turnpage();
			})
		}
	}
	
	function jumpAdd() {
		$("#user-form").find("input,select").val("");
		$("#user-dialog").modal("show");
	}
	
	function saveUser() {
		$.ajax({
			url:"/user/save",
			type:"post",
			data:$("#user-form").serialize()
		}).done(function(data){
			alert(data.msg);
			if(data.isSuccess) {
				$('#user-dialog').modal('hide');
			}
		})
	}
	
	$(function() {
		$('#user-dialog').on('hidden.bs.modal', function (e) {
            turnpage();
        })
	})
	
</script>
<!-- content starts -->
<div>
	<ul class="breadcrumb">
	    <li>用户管理</li>
	    <li>用户管理</li>
	</ul>
</div>

<div class="row">
    <div class="box col-md-12">
	    <div class="box-inner">
		    <div class="box-header well" data-original-title="">
	        	<h2><i class="glyphicon glyphicon-user"></i> 用户管理</h2>

        		<div class="box-icon">
		            <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
		            <a href="#" class="btn btn-minimize btn-round btn-default"><i
		                    class="glyphicon glyphicon-chevron-up"></i></a>
		            <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
		        </div>
    		</div>
    		<div class="box-content">
    			<a href="javascript:;" class="btn btn-default" onclick="jumpAdd();">新增</a><p/>
    			<!-- <div class="alert alert-info">For help with such table please check <a href="http://datatables.net/" target="_blank">http://datatables.net/</a></div> -->
			    <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
			    <thead>
			    <tr>
			        <th>登录名</th>
			        <th>用户名</th>
			        <th>类型</th>
			        <th>创建时间</th>
			        <th>操作</th>
			    </tr>
			    </thead>
			    <tbody>
			    <c:forEach items="${userPage.list }" var="user">
			    <tr>
			        <td class="center">${user.loginname }</td>
			        <td class="center">${user.username }</td>
			        <td class="center">${user.type_display }</td>
			        <td class="center">${user.create_time }</td>
			        <td class="center">
			            <!-- <a class="btn btn-success" href="#">
			                <i class="glyphicon glyphicon-zoom-in icon-white"></i>
			                View
			            </a> -->
			            <a class="btn btn-info" href="javascript:;" onclick='editUser("${user.id}");'>
			                <i class="glyphicon glyphicon-edit icon-white"></i> 编辑
			            </a>
			            <a class="btn btn-danger" href="javascript:;" onclick='delUser("${user.id}");'>
			                <i class="glyphicon glyphicon-trash icon-white"></i> 删除
			            </a>
			        </td>
			    </tr>
			    </c:forEach>
			    </tbody>
			    </table>
    		</div>
    	</div>
    </div>
    <!--/span-->

</div><!--/row-->

<div class="col-md-12">
	<div class="dataTables_info">第${userPage.pageNumber }/${userPage.totalPage }页,共${userPage.totalRow }条记录</div>
</div>
<p:page pageNumber="${userPage.pageNumber }" totalPage="${userPage.totalPage }"
	 totalRow="${userPage.totalRow }" width="12"/>
<!-- <div id="user-add-div">
	
</div> -->
<jsp:include page="user_add.jsp"/>